//
//  UIBarButtonItem+Extension.swift
//  Weibo
//
//  Created by Apple on 2017/7/21.
//  Copyright © 2017年 KY. All rights reserved.
//

import UIKit
//  扩展里面不能定义指定构造函数，只能定义便利构造函数
extension UIBarButtonItem {
    //  提供便利构造函数
    //  参数默认值，如果不传该参数，默认值为nil
    convenience init(title: String, imageName: String? = nil, target: Any?, action: Selector) {
        let button = UIButton()
        button.addTarget(target, action: action, for: .touchUpInside)
        button.setTitle(title, for: .normal)
        if imageName != nil {
            button.setImage(UIImage(named: imageName!), for: .normal)
        }
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        button.sizeToFit()
        self.init(customView: button)
    }
}
